Welcome to JavaScript!

3.03 字符串运算符

1、 JavaScript 中的+和+=运算符除了可以进行数学运算外,还可以用来拼接字符串,其中

1)+运算符表示将运算符左右两侧的字符串拼接到一起;

2)+两侧只要有一侧是字符窜,表示连接,并不是加法;

3)+=运算符表示先将字符串进行拼接,然后再将结果赋值给运算符左侧的变量。

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>Title</title>

<script type="text/javascript">

var a=3+"3"; //返回值:33

var x = "Hello ";

document.write('x的返回值为:',x,"<br>");

var y = "World!";

document.write('y的返回值为:',y,"<br>");

x += y; //返回值:Hello World!

document.write('3+"3"的返回值为:',a,"<br>");

document.write('x += y;的返回值为:',x,"<br>");

</script>

</head>

<body>

</body>

</html>

返回值:

x的返回值为:Hello

y的返回值为:World!

3+"3"的返回值为:33

x += y;的返回值为:Hello World!